<?php

namespace app\admin\model;

use think\Model;
use think\Db;

class Importschool extends Model
{

    

    

    // 表名
    protected $name = 'importschool';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'init';

    // 定义时间戳字段名
    protected $createTime = 'create_time';
    protected $updateTime = 'update_time';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'create_time_text',
        'update_time_text',
        'admission_starttime_text',
        'admission_endtime_text',
        'is_check_text'
    ];
    
    public function getIsCheckTextAttr($value, $data)
    {
        $info = Db::name('outsideschool')->where(['importschool_id'=>$data['id']])->find();
        return $info['is_check'];
    }

    public function getCreateTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['create_time']) ? $data['create_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getUpdateTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['update_time']) ? $data['update_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getAdmissionStarttimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['admission_starttime']) ? $data['admission_starttime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getAdmissionEndtimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['admission_endtime']) ? $data['admission_endtime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setCreateTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setUpdateTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setAdmissionStarttimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setAdmissionEndtimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }


}
